package com.sskj.wallet.http;

import android.text.TextUtils;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.GetRequest;
import com.lzy.okgo.request.PostRequest;
import com.sskj.common.base.HttpData;
import com.sskj.lib.bean.CoinBean;
import com.sskj.lib.bean.CoinEnum;
import com.sskj.lib.bean.CoinType;
import com.sskj.lib.bean.PageBean;
import com.sskj.lib.util.EncodeUtils;
import com.sskj.lib.util.PopUtil;
import com.sskj.wallet.bean.AddressListBean;
import com.sskj.wallet.bean.AwardBean;
import com.sskj.wallet.bean.BannerBean;
import com.sskj.wallet.bean.CoinListBean;
import com.sskj.wallet.bean.CoinPriceBean;
import com.sskj.wallet.bean.CreateBean;
import com.sskj.wallet.bean.EthBalanceBean;
import com.sskj.wallet.bean.GasPriceBean;
import com.sskj.wallet.bean.NoticeBean;
import com.sskj.wallet.bean.RecordInfoBean;
import com.sskj.wallet.bean.TransferRecordBean;
import com.sskj.wallet.bean.TransferResultBean;

import java.util.List;

/**
 * 作者 :吕志豪
 * 简书：https://www.jianshu.com/u/6e525b929aac
 * github：https://github.com/lvzhihao100
 * 描述：
 * 创建时间：2018-10-15 14:08
 */
public class HttpService {


    public PostRequest<HttpData<NoticeBean>> getBanner() {
        return OkGo.<HttpData<NoticeBean>>post(HttpConfig.BASE_URL + HttpConfig.BANNER);
    }

    public PostRequest<HttpData<CreateBean>> createAccount(boolean isFirst, String coinType, String action, String input, String pwd, String path) {
        return OkGo.<HttpData<CreateBean>>post(HttpConfig.BASE_URL + HttpConfig.CREATE_ACCOUNT)
                .params("isfirst", isFirst)
                .params("cointype", coinType)
                .params("action", action)
                .params("input", TextUtils.isEmpty(input) ? "" : EncodeUtils.encodeAES2B(input))
                .params("pass", pwd)
                .params("path", path);
    }

    public PostRequest<HttpData<List<CoinListBean>>> getCoinList() {
        return OkGo.<HttpData<List<CoinListBean>>>post(HttpConfig.BASE_URL + HttpConfig.GET_COIN_LIST)
                .params("type", CoinEnum.coinEnum.getId());
    }

    public PostRequest<HttpData<TransferResultBean>> transferEth(String memo,String fromPri, String toAddr, String amount, String gasLimit, String gasPriceGwei) {
        return OkGo.<HttpData<TransferResultBean>>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_ETH)
                .params("fromPri", EncodeUtils.encodeAES2B(fromPri))
                .params("toAddr", toAddr)
                .params("amount", amount)
                .params("gasLimit", gasLimit)
                .params("memo", memo)
                .params("gasPriceGwei", gasPriceGwei);

    }

    public PostRequest<HttpData<TransferResultBean>> transferEthToken(String memo,String fromPri, String toAddr, String cttAddr, String amount, String gasLimit, String gasPriceGwei) {
        return OkGo.<HttpData<TransferResultBean>>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_ETH_TOKEN)
                .params("fromPri", EncodeUtils.encodeAES2B(fromPri))
                .params("toAddr", toAddr)
                .params("cttAddr", cttAddr)
                .params("amount", amount)
                .params("memo", memo)
                .params("gasLimit", gasLimit)
                .params("gasPriceGwei", gasPriceGwei);

    }

    public PostRequest<HttpData<EthBalanceBean>> getEthBalance(String addr) {
        return OkGo.<HttpData<EthBalanceBean>>post(HttpConfig.BASE_URL + HttpConfig.BALANCE_ETH)
                .params("addr", addr);
    }

    public PostRequest<HttpData<PageBean<TransferRecordBean>>> getTransferRecord(String address, String code, String type, String state, String p, String size) {
        return OkGo.<HttpData<PageBean<TransferRecordBean>>>post(HttpConfig.BASE_URL + HttpConfig.TRANSFER_RECORD)
                .params("address", address)
                .params("type", type)
                .params("coin", code)
                .params("status", state)
                .params("p", p)
                .params("size", size)
                ;
    }

    public PostRequest<HttpData<GasPriceBean>> getGasPrice() {
        return OkGo.<HttpData<GasPriceBean>>post(HttpConfig.BASE_URL + HttpConfig.GAS_PRICE)
                ;
    }

    public PostRequest<HttpData<CoinPriceBean>> getCoinPrice() {
        return OkGo.<HttpData<CoinPriceBean>>post(HttpConfig.BASE_URL + HttpConfig.COIN_PRICE)
                ;
    }

    public PostRequest<HttpData> actAddress(String address, String act, String notes, String mobile, String type) {
        return OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.ACT_ADDRESS)
                .params("address", address)
                .params("act", act)
                .params("notes", notes)
                .params("mobile", mobile)
                .params("type", type)
                ;
    }

    public GetRequest<HttpData<AddressListBean>> addressList() {
        return OkGo.<HttpData<AddressListBean>>get(HttpConfig.BASE_URL + HttpConfig.ADDRESS_LIST)

                ;
    }

    public PostRequest<HttpData<AwardBean>> checkAward(String addr,String type) {
        return OkGo.<HttpData<AwardBean>>post(HttpConfig.BASE_URL + HttpConfig.CHECK_AWARD)
                .params("addr",addr)
                .params("type",type)
                ;
    }

    public PostRequest<HttpData<RecordInfoBean>> getRecordInfo(String hashstr) {
        return OkGo.<HttpData<RecordInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.RECORD_INFO)
                .params("hashstr",hashstr)
                ;
    }
}